﻿# coding=utf-8
# /usr/bin/env python
import xlsxwriter, xlrd
import csv
import sys, os.path
file= 'data.csv'
if not os.path.isfile(file):
    print('文件路径不存在')
    sys.exit()
file_open = open(file, 'r')
reader = csv.reader(file_open)
workbook = xlsxwriter.Workbook('zm6.xlsx')  # 创建一个excel文件
worksheet = workbook.add_worksheet()  # 创建一个工作表对象
temp=[]
for line in reader:
     temptemp = [[], [], []]
     temptemp[0]=line[4]
     temptemp[1]=line[13]
     temptemp[2]=line[15]
     temp.append(temptemp)
x=0
for a in temp:
    y=0
    for b in a:
        worksheet.write(x, y, b)
        y+=1
    x+=1
workbook.close()

workbook.close()
# fname = 'test.xlsx'
# data = xlrd.open_workbook(fname)  # 打开fname文件
# data.sheet_names()  # 获取xls文件中所有sheet的名称
# table = data.sheet_by_index(0)  # 通过索引获取xls文件第0个sheet
# nrows = table.nrows  # 获取table工作表总行数
# ncols = table.ncols  # 获取table工作表总列数

# worksheet.set_column(0, ncols, 22)  # 设定列的宽度为22像素
# temp=[[0 for i in range(ncols)]for j in range(nrows)]
# for i in range(nrows):
#     for j in range(ncols):
#         temp[i][j] = table.cell_value(i, j, )  # 获取第i行中第j列的值
# for i in range(nrows):
#     for j in range(ncols):
#         # cell_value=temp[i][j]
#         # print(cell_value)
#         worksheet.write(i, j, temp[i][j])
# workbook.close()